package com.uroad.jilinpda.presenter;


import com.uroad.jilinpda.common.BaseActivity;

public class BaseMvpPresenter <v extends BaseActivity>{
    private v mvpView;

    public void attachView(v mvpView){
        this.mvpView = mvpView;
    }

    public void detachView(){
        mvpView = null;
    }
    /**
     * 判断view是否为空
     */
    public boolean isAttchView(){
        return mvpView != null;
    }
    /**
     * 返回目标view
     */
    public v getMvpView(){
        return mvpView;
    }
    /**
     * 检查绑定
     */
    public v checkViewAttach(){
        if (!isAttchView()){
            throw new MvpViewNotAttachedException();
        }else{
            return mvpView;
        }
    }
    /**
     * 自定义
     */
    public static class MvpViewNotAttachedException extends RuntimeException {
        public MvpViewNotAttachedException(){
            super("请求数据前请先调用attachView(MvpView)方法与View建立连接");
        }
    }
}
